package com.iot08.api.service;

import com.iot08.api.dto.res.DrinkDataRes;
import com.iot08.common.entity.app.DrinkData;
import com.iot08.common.service.base.BaseService;
import com.iot08.common.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DrinkDataService extends BaseService<DrinkData> {
    private static final Logger log = LoggerFactory.getLogger(DrinkDataService.class);

    public DrinkDataService() {
    }

    public List<DrinkData> queryTodayDrinkData(String imei, String nowDate) {
        Query query = new Query(Criteria.where("imei").is(imei).and("date").is(nowDate));
        return this.find(query);
    }

    public List<DrinkData> queryTodayDrinkData(String imei) {
        String nowDate = DateUtil.dateToStr(new Date(), "yyyy-MM-dd");
        Query query = new Query(Criteria.where("imei").is(imei).and("date").is(nowDate));
        return this.find(query);
    }

    /**
     * @description 查询当天的喝水量信息
     * @author cwj
     * @param [imei]
     * @return java.util.List<com.iot08.api.dto.res.DrinkDataRes>
     * @date @time 2024/12/2 15:32
     **/
    public List<DrinkDataRes> queryTodayDrinkDataRes(String imei) {
        String nowDate = DateUtil.dateToStr(new Date(), "yyyy-MM-dd");
        Query query = new Query(Criteria.where("imei").is(imei).and("date").is(nowDate));
        return this.mongoTemplate.find(query, DrinkDataRes.class, "drink_data");
    }
}